<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>SqlMap配置</title>
    <script type="text/javascript" src="/script/mootools.js"></script>
    <script type="text/javascript" src="/script/mootools-more.js"></script>
    <link rel="stylesheet" type="text/css" href="/script/jspxnet-ui.css"/>
    <script type="text/javascript" src="/script/jspxnet.js"></script>
    <script type="text/javascript" src="/script/jspxnet-ui-roc.js"></script>
    <script type="text/javascript" src="/script/codemirror/lib/codemirror.js"></script>
    <link href="/script/codemirror/lib/codemirror.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="/script/codemirror/mode/xml/xml.js"></script>
    <script type="text/javascript" src="/script/codemirror/mode/javascript/javascript.js"></script>
    <script type="text/javascript" src="/script/codemirror/mode/css/css.js"></script>
    <script type="text/javascript" src="/script/codemirror/mode/sql/sql.js"></script>
    <link href="/share/mskin/default/css.css" rel="stylesheet" type="text/css"/>
	<script>
    var app = false;
    var editor = false;
	var namespaceDlg = false;

    var id = getUrlParam("id") - 0;
    window.addEvent('domready', function () {
		 editor = CodeMirror.fromTextArea($('context'), {
                lineNumbers: true,
                mode: "text/x-sql",
                indentUnit: 4,
                indentWithTabs: true
        });

        $('saveBtn').addEvent('click', function () {
               var posts = getFormJson("sqlMapConfForm");
			   posts.id = id;
			   posts.context = editor.getValue();
               //添加接口
               var url = '/devcenter/sqlmap/conf/save.jwc';
               new Request.ROC({
                        'url': url,data:posts,
                        onSuccess: function (obj) {
                            if (obj.success == 1) {
                                new JDialog.Pop({
                                    title: '提示信息',
                                    message: obj.message
                                }).show();
                            } else {
                                new JDialog.Alert({
                                    title: '提示信息',
                                    message: obj.message
                                }).show();
                            }
                        }
             }).post();
        });

		$('testBtn').addEvent('click', function () {
               var posts = getFormJson("sqlMapConfForm");
			   var postData = {};
			 
			   postData.exeName = posts.name;
			   postData.namespace = posts.namespace;
			   postData.currentPage = 1;
			   postData.count = 10;

               //添加接口
               var url = '/dynout/call/sqlmap.jwc';
               new Request.ROC({
                        'url': url,data:postData,
                        onSuccess: function (obj) {
						 var msg = new Element('textarea',{'style':'width:98%; height:300px;','html':JSON.encode(obj)});
                         new JDialog({
                                    title: '返回结果',
									width:640,
									height:400,
                                    message: msg
                           }).show();
                        }
             }).post();
        });
		
		$('testPageBtn').addEvent('click', function () {
               var posts = getFormJson("sqlMapConfForm");
			   var postData = {};
			 
			   postData.exeName = posts.name;
			   postData.namespace = posts.namespace;
			   postData.currentPage = 1;
			   postData.count = 10;

               //添加接口
               var url = '/dynout/call/sqlmap/page.jwc';
               new Request.ROC({
                        'url': url,data:postData,
                        onSuccess: function (obj) {
						 var msg = new Element('textarea',{'style':'width:98%; height:300px;','html':JSON.encode(obj)});
                         new JDialog({
                                    title: '返回结果',
									width:640,
									height:400,
                                    message: msg
                           }).show();
                        }
             }).post();
        });
		
		


		$('selectNamespace').addEvent('click', function (e) {
                e.stop();
                if (namespaceDlg) {
                    //重新生成
                    namespaceDlg.close();
                    delete namespaceDlg;
                }

                var columnModels =
                    [
                        {name: "namespace", caption: "选择", type: "string", edit: true, input: "selectbox", width: 30},
                        {
                            name: "namespace",
                            caption: "命名空间",
                            type: "string",
                            edit: true,
                            input: "text",
                            align: "left",
                            width: 280
                        }
                    ];
                namespaceDlg = new JDialog.DataTable({
                    title: '选择命名空间',
                    height: 460,
                    width: 440,
                    jsonUrl: '/devcenter/codemaker/list/namespace.jwc',
                    buttons: [],
                    columnModels: columnModels,
                    multiselect: false,
                    find: false,
                    pagination: false,
                    callback: function (selects) {
                        for (var i = 0; i < selects.length; i++) {
                            $('namespace').set('value', selects[i].namespace);
                        }
                    }
                });
                namespaceDlg.show();

        });

		loadData();

    });

	function loadData() 
	{
              if (id <= 0) id = 0;
              new Request.ROC({
                        'url': '/devcenter/sqlmap/conf/detail/' + id + '.jwc',
                        onSuccess: function (obj) {
                            if (obj.success) 
							{
								setFormJson('sqlMapConfForm',obj.data);
								editor.setValue(obj.data.context);								
                            }
                        }
             }).send();
    }
</script>
</head>
<body>
<div class="formContainer mWrap">
    <div class="mTitPanel addBoardLogo">
        SqlMap配置
    </div>
    <div class="mConPanel">
        <div id="helpTip"></div>
        <form id="sqlMapConfForm" >
                        <div class="row">
                            <label class="tit" for="executeType">执行类型</label>
                            <div class="con">
                                <select name="executeType" id="executeType">
                                        <option value="0">QUERY</option>
                                        <option value="1">UPDATE</option>
                                        <option value="2">EXECUTE</option>
                                </select>
                                <span id="executeTypeMsg" class="note"></span>
                            </div>
                        </div>
                      <div class="row">
                        <label class="tit" for="databaseType">数据库类型</label>
                        <div class="con">
								<select name="databaseType" id="databaseType">
                                        <option value="">默认</option>
                                        <option value="MySQL">MySQL</option>
                                        <option value="PostgreSQL">PostgreSQL</option>
                                        <option value="Oracle">Oracle</option>
                                        <option value="Dm">Dm</option>
                                        <option value="Interbase">Interbase</option>
                                        <option value="MsSql">MsSql</option>
                                        <option value="HSQL">HSQL</option>
                                        <option value="DB2">DB2</option>
                                        <option value="Firebird">Firebird</option>
                                        <option value="Sqlite">Sqlite</option>
                                        <option value="Smalldb">Smalldb</option>
                                </select>
                            <span id="databaseTypeMsg" class="note"></span>
                        </div>
                    </div>
                       <div class="row">
                        <label class="tit" for="name">名称</label>
                        <div class="con">
                            <input id="name" name="name" type="text"/>
                            <span id="nameMsg" class="note">默认:java方法完整路径</span>
                        </div>
                      </div>
                    <div class="row">
                        <label class="tit" for="caption">描述</label>
                        <div class="con">
                            <input id="caption" name="caption" type="text"/>
                            <span id="captionMsg" class="note"></span>
                        </div>
                    </div>
                    <div class="row">
                        <label class="tit" for="resultType">返回类型</label>
                        <div class="con">
                            <input id="resultType" name="resultType" type="text" />
                            <span id="resultTypeMsg" class="note">返回的java类路径</span>
                        </div>
                    </div>
                        <div class="row">
                            <label class="tit" for="nexus">载入关联映射</label>
                            <div class="con">
                                <select name="nexus" id="nexus" v-model="nexus">
                                        <option value="0">NO</option>
                                        <option value="1">YES</option>
                                </select>
                                <span id="nexusMsg" class="note"></span>
                            </div>
                        </div>
                        <div class="row">
                            <label class="tit" for="queryModel">查询模式</label>
                            <div class="con">
                                <select name="queryModel" id="queryModel" v-model="queryModel">
                                        <option value="0">LIST</option>
                                        <option value="1">SINGLE</option>
                                        <option value="2">COUNT</option>
                                </select>
                                <span id="queryModelMsg" class="note"></span>
                            </div>
                        </div>
                    <div class="row">
                        <label class="tit" for="interceptor">拦截器</label>
                        <div class="con">
                            <input id="interceptor" name="interceptor" type="text" v-model:value="interceptor"/>
                            <span id="interceptorMsg" class="note">sql拦截器完整类路径</span>
                        </div>
                    </div>
                    <div class="row">
                        <label class="tit" for="currentPage">分页变量</label>
                        <div class="con">
                            <input id="currentPage" name="currentPage" type="text" v-model:value="currentPage"/>
                            <span id="currentPageMsg" class="note">测试默认为:1</span>
                        </div>
                    </div>
                    <div class="row">
                        <label class="tit" for="count">分页行数变量</label>
                        <div class="con">
                            <input id="count" name="count" type="text" v-model:value="count"/>
                            <span id="countMsg" class="note">测试默认为:10</span>
                        </div>
                    </div>
			        <div class="row">
                        <label class="tit" for="namespace">命名空间namespace</label>
                        <div class="con">
                            <input id="namespace" name="namespace" type="text" v-model:value="namespace"/>
							<img id="selectNamespace" for="namespace" src="/script/images/popgrid.png" class="jSelectButton"/>
                        </div>
                    </div>      
                    <div class="columnPanel">
                        <label class="tit" for="context">SQL:</label>
						<button id="testBtn" type="button"  class="jDefButton"><i class="jIcoAuditImage"></i>测试</button>
						<button id="testPageBtn" type="button"  class="jDefButton"><i class="jIcoAuditImage"></i>分页测试</button>
                        <div class="con">
						    <textarea name="context" id="context" style="width:98%;height:300px;"></textarea>
                            <span id="contextMsg" class="note"></span>
                        </div>
                    </div>

		           <div class="buttonPanel">
				        <button id="saveBtn" name="method" value="save" type="button"  class="jDefButton"><i class="jIcoSave"></i>确定</button>
						<input id="id" name="id" type="hidden" />
		          </div>
        </form>
    </div>
</div>
</body>
</html>
